﻿<? include("conn.php") ?>

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <?php include("public/cssjs.php");?>
    <title>产品列表</title>
    <link rel="stylesheet" href="lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="pos-r">
<div class="pos-a" style="width:200px;left:0;top:0; bottom:0; height:100%; border-right:1px solid #e5e5e5; background-color:#f5f5f5; overflow:auto;">
    <ul id="treeDemo" class="ztree"></ul>
</div>
<div style="margin-left:200px;">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 产品列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <form name="frmtj" method="get" action="?">
            <div class="text-c"> 日期范围：
                <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}' })" id="logmin" name="logmin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d' })" id="logmax" name="logmax" class="input-text Wdate" style="width:120px;">
                <input type="text" name="keyword" id="" placeholder="产品名称" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜产品</button>
            </div>
        </form>
        <?
        $keyword=$_GET["keyword"];
        $logmin=$_GET["logmin"];
        $logmax=$_GET["logmax"];
        $cataid=Request_fildes("id","newscata_product","title='".$_REQUEST["cataname"]."'");
        if($cataid){ $cond=" type=".$cataid;}else{ $cond=" 1=1 "; }
        if($keyword!=""){ $cond.=" and title like '%".$keyword."%'";}
        if($logmin!=""){ $cond.=" and adate>='".$logmin."'";}
        if($logmax!=""){ $cond.=" and adate<='".$logmax."'";}

        $conn=new Mysql();
        $sql = "select * from products where $cond order by adate desc";
        $page_size = 5;					 //定义每页显示多少记录
        $num_cnt = mysqli_num_rows($conn->query($sql)); //获取总记录数
        $page_cnt = ceil($num_cnt/$page_size);  //计算总页数
        if(isset($_GET["page"])){
            $page = intval($_GET["page"]);
        }else{
            $page = 1;
        }
        if ($page<1)
        {
            $page=1;
        }
        elseif ($page>$page_cnt)
        {
            $page=$page_cnt;
        }
        $query_start = ($page - 1 ) * $page_size;   //计算每页开始的记录号
        $query_sql = $sql." limit $query_start,$page_size"; //使用limit获取记录

        ?>
        <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a class="btn btn-primary radius" onclick="news_add('添加产品','product-add.php')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 添加产品</a></span> <span class="r">共有数据：<strong><?=$num_cnt?></strong> 条</span> </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="40"><input name="" type="checkbox" value=""></th>
                    <th width="40">ID</th>

                    <th width="180">标题名称</th>
                    <th width="60">所属分类</th>
                    <th width="60">缩略图</th>
                    <th width="60">浏览量</th>
                    <th width="120">价格</th>
                    <th width="100">发布时间</th>
                    <th width="60">发布状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                <?
                if($num_cnt>0)
                {
                    $row=$conn->getAll($query_sql);
                    foreach($row as $key=>$rs){
                        ?>

                        <tr class="text-c va-m">
                            <td><input name="" type="checkbox" value="<?php echo $rs["id"];?>"></td>
                            <td><?php echo $rs["id"];?></td>

                            <td class="text-l"><a style="text-decoration:underline !important"  href="/view.php?id=<?php echo $rs["id"];?>" target="_blank" ><b class="text-success"><?php echo killword($rs["title"],15)?></b> <?php echo killword($rs["title_f"],22);?></a>
                                <?php if($rs["is_hot"]==1){ echo '<font color="#FF0000">[精]</font>';}if($rs["is_tejia"]==1){ echo '<font color="#009900">[特价]</font>';}?>
                            </td>
                            <td class="text-l"><?php echo Request_fildes("title","newscata_product"," id=".$rs["type"]);?></td>
                            <td class="text-l"><img src="/pic/<?php echo $rs["pic"];?>" onerror="this.src='/pic/error.jpg'" width="100" height="100"></td>
                            <td class="text-l"><?php echo $rs["Linkcount"];?></td>
                            <td class="text-l">&yen;<?php echo $rs["ys_s_price"]."/&yen;".$rs["ys_e_price"];?></td>
                            <td><span class="price"><?php echo date("Y-m-d H:i:s",strtotime($rs["adate"]));?></span> </td>
                            <td class="td-status">
                                <?php echo $rs["Display_home"]?'<span class="label label-success radius">已发布</span>':'<span class="label label-defaunt radius">已停用</span>';?>
                            </td>
                            <td class="td-manage">

                                <?php if($rs["Display_home"]==1){
                                    ?>
                                    <a style="text-decoration:none" onClick="news_stop(this,'<?php echo $rs["id"];?>')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
                                    <?php
                                }else{
                                    ?>
                                    <a style="text-decoration:none" onClick="news_start(this,'<?php echo $rs["id"];?>')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>
                                    <?php
                                }?>
                                <a style="text-decoration:none" class="ml-5" onClick="news_edit('产品编辑','product-edit.php?id=<?php echo $rs["id"];?>','<?php echo $rs["id"];?>')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a style="text-decoration:none" class="ml-5" onClick="news_del(this,'<?php echo $rs["id"];?>')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                        </tr>

                        <?
                    }
                    ?>
                    <Tr><Td colspan="10"><?php Controlnews($num_cnt,$page_cnt,$page,$table_style,$font_style);?></Td></Tr>

                    <?php
                }else{
                    ?>
                    <Tr><Td colspan="10" align="center">暂无产品信息</Td></Tr>
                    <?
                }
                ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/h-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/h-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">

    var setting = {
        view: {
            dblClickExpand: false,
            showLine: false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable:true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        callback: {
            beforeClick: function(treeId, treeNode) {
                var zTree = $.fn.zTree.getZTreeObj("tree");
                if (treeNode.isParent) {
                    zTree.expandNode(treeNode);
                    return false;
                } else {
                    window.location='?cataname='+treeNode.name;
                    //alert(treeNode.name);
                    //demoIframe.attr("src",treeNode.file + ".html");
                    return true;
                }
            }
        }
    };

    $(document).ready(function(){
        var zNodes=[];
        $.ajax({
            type: 'GET',
            url: 'json/procata.php',
            data:{'Type':'checkall'},
            dataType: 'json',
            success: function(data){
                zNodes=data;
                var t = $("#treeDemo");
                t = $.fn.zTree.init(t, setting, zNodes);
                demoIframe = $("#testIframe");
                var zTree = $.fn.zTree.getZTreeObj("tree");
                console.log(zNodes)
            },
            error:function(data) {
                console.log(data.msg);
            },
        });


    });

    /*$('.table-sort').dataTable({
        "aaSorting": [[ 1, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
          {"orderable":false,"aTargets":[0,7]}// 制定列不参与排序
        ]
    });*/
    /*产品-添加*/
    function news_add(title,url){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    /*产品-查看*/
    function news_show(title,url,id,w,h){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
    /*产品-审核*/
    function news_shenhe(obj,id){
        layer.confirm('审核产品上线？', {
                btn: ['上线','下架'],
                shade: false
            },
            function(){
                $.ajax({
                    type: 'POST',
                    url: 'json/products.php',
                    data:{'Type':'checkstate','isstate':1,'id':id},
                    dataType: 'json',
                    success: function(data){
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="news_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
                        $(obj).remove();
                        layer.msg('已发布', {icon:6,time:1000});
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });

            },
            function(){
                $.ajax({
                    type: 'POST',
                    url: 'json/products.php',
                    data:{'Type':'checkstate','isstate':0,'id':id},
                    dataType: 'json',
                    success: function(data){
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="news_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
                        $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
                        $(obj).remove();
                        layer.msg('已发布', {icon:6,time:1000});
                    },
                    error:function(data) {
                        console.log(data.msg);
                    },
                });
            });
    }
    /*用户-停用*/
    function news_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type: 'POST',
                url: 'json/products.php',
                data:{'Type':'checkstate','isstate':0,'id':id},
                dataType: 'json',
                success: function(data){

                    $(obj).parents("tr").find(".td-manage").prepend('<a onClick="news_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
                    $(obj).remove();
                    layer.msg('已停用!',{icon: 5,time:1000});
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*用户-启用*/
    function news_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'json/products.php',
                data:{'Type':'checkstate','isstate':1,'id':id},
                dataType: 'json',
                success: function(data){
                    $(obj).parents("tr").find(".td-manage").prepend('<a onClick="news_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
                    $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                    $(obj).remove();
                    layer.msg('已启用!', {icon: 6,time:1000});
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }

    /*产品-申请上线*/
    function news_shenqing(obj,id){
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
        $(obj).parents("tr").find(".td-manage").html("");
        layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
    }

    /*产品-编辑*/
    function news_edit(title,url,id){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /*产品-删除*/
    function news_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'json/products.php',
                data:{'Type':'delete','id':id},
                dataType: 'json',
                success: function(data){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>